import { http, instance2 } from "../utils/http"

//获取图形验证码
export const userCode = (p) => http.get("/graphicalCode.php", p)
//注册获取注册短信验证码
export const userRegister = (p) => http.get("/phoneRegisterYZM.php", p)
//注册
export const userRegisterByMobile = (p) =>
  http.get("/phoneRegisterByMobile.php", p)
//登录
export const userLogin = (p) => http.get("/phoneLogin.php", p)
//退出登录
export const userOut = (p) => http.get("/phoneLogout.php", p)

//广告
export const advert = (p) => http.get("/tjdata/advert/advert.json", p)

//走势图
function getTrend({ gid }) {
  return instance2({
    url: "/tjdata/omi/" + gid + "/trend.json?rnd=" + Math.random(),
    method: "get",
  }).then((v) => {
    return {
      data: {
        status: "_0000",
        message: "成功",
        data: v.data,
      },
    }
  })
}
//详情广告
function getbanner({ banner }) {
  return instance2({
    url: "/tjdata/ad/" + banner + "/ad.json?rnd=" + Math.random(),
    method: "get",
  }).then((v) => {
    return {
      data: {
        status: "_0000",
        message: "成功",
        data: v.data,
      },
    }
  }).catch(v=>{
    console.log(v)
  })
}
// 详情页内容
function getcontent({ gid, pid }) {
  return instance2({
    url: "/tjdata/game/" + gid + "/" + pid + ".json?rnd=" + Math.random(),
    method: "get",
  }).then((v) => {
    return {
      data: {
        status: "_0000",
        message: "成功",
        data: v.data,
      },
    }
  })
}
//历史记录
function gethistory({ gid }) {
  return instance2({
    url: "/tjdata/game/nearFuture/" + gid + ".json?rnd=" + Math.random(),
    method: "get",
  }).then((v) => {
    return {
      data: {
        status: "_0000",
        message: "成功",
        data: v.data,
      },
    }
  })
}

function getHistoryRecord({ mid, id }) {
  return instance2({
    url: "/tjdata/news/" + mid + "/" + id + ".json?rnd=" + Math.random(),
    method: "get",
  }).then((v) => {
    return {
      data: {
        status: "_0000",
        message: "成功",
        data: v.data,
      },
    }
  })
}

function getAdvertia() {
  return instance2({
    url: "/tjdata/ad/1/ad.json?rnd=" + Math.random(),
    method: "get",
  }).then((v) => {
    return {
      data: {
        status: "_0000",
        message: "成功",
        data: v.data,
      },
    }
  })
}
// 获取广告
function getAdverti({ type }) {
  return instance2({
    url: "/getAdverti.php",
    method: "POST",
    params: {
      type,
    },
  })
}


//活动中心
export const getActivityCore = (p) => http.get("/getActivityCore.php", p)

export {
  getTrend,
  getAdverti,
  getAdvertia,
  getbanner,
  getcontent,
  gethistory,
  getHistoryRecord,
}
